// ==UserScript==
// @name         B站直播表情辅助 for 华小科（小南莓联动版）
// @namespace    https://space.bilibili.com/672455305/
// @version      8.1
// @description  为华小科直播间弹幕表情包提供快捷支持，并联动小南莓直播间（支持 Surface 等设备触屏）
// @author       磷元素P 神马都是包子 文诗不是闻诗
// @grant        none
// @match        https://live.bilibili.com/*
// @updateURL    https://gitee.com/linyuansup/bilibilihxk-upd/raw/master/script.user.js
// @downloadURL  https://gitee.com/linyuansup/bilibilihxk-upd/raw/master/script.user.js
// ==/UserScript==
function click_fun(id_data, text_data, event, character) {
    for (let i = 0; i < id_data.length; i++)
        if (event.target.id == id_data[i]) var t = text_data[i];
    insertData(t, character);
}
function createHTML(id_data, text_data, cha) {
    var return_data = "<div class=\"gift-panel base-panel live-skin-coloration-area\" data-v-6379e588=\"\">";
    for (let i = 0; i < id_data.length; i++)
        return_data += "<div data-v-131e74b2=\"\" data-v-6379e588=\"\" role=\"button\"class=\"gift-item dp-i-block p-relative v-top pointer bg-cover live-skin-separate-area-hover gift-id-30877 normal buy small\"id=\"" + id_data[i] + "\"><img data-v-131e74b2=\"\" src=\"https://gitee.com/linyuansup/bilibilihxk-upd/raw/master/" + cha + "/" + id_data[i] + ".png\" class=\"img\"id=\"" + id_data[i] + "\"><div data-v-7207ff37=\"\" class=\"info\" id=\"" + id_data[i] + "\"><p data-v-7207ff37=\"\" class=\"label live-skin-main-text\">" + text_data[i] + "</p></div></div>";
    return_data += "</div>";
    return return_data;
};
function insertData(t, cha) {
    if (t !== undefined) {
        var inputBox1 = document.getElementsByClassName('chat-input border-box')[0], inputBox, inputBox2 = document.getElementsByClassName('chat-input border-box')[1], has_not_pass = true, sta, data = "[" + cha + "_" + t + "]";
        if (inputBox1 == "[object HTMLTextAreaElement]") {
            inputBox = inputBox1;
            sta = true;
        } else {
            if (inputBox2 == "[object HTMLTextAreaElement]") {
                inputBox = inputBox2;
                sta = true;
            } else {
                navigator.clipboard.writeText(data);
                if (has_not_pass) {
                    sta = has_not_pass = false;
                    alert("程序出错导致无法填充，但表情包已复制到剪贴板，您可以自行粘贴");
                };
            };
        };
        if (sta) {
            var btn = document.getElementsByClassName('bl-button live-skin-highlight-button-bg live-skin-button-text bl-button--primary bl-button--small')[0];
            inputBox.value = data;
            inputBox.dispatchEvent(new InputEvent('input'));
            setTimeout(() => {
                btn.click();
            }, 25);
        };
    };
};
(function () {
    (() => {
        'use strict';
        const location = window.location.toString();
        const matches = [
            /https?:\/\/live\.bilibili\.com\/22536559(?:\?\S+)?$/,
            /https?:\/\/live\.bilibili\.com\/21745484(?:\?\S+)?$/,
            /https?:\/\/live\.bilibili\.com\/21741192(?:\?\S+)?$/,
            /https?:\/\/live\.bilibili\.com\/3126548(?:\?\S+)?$/
        ];
        if (matches.every(m => location.match(m) === null)) return;
        let div_hxk_1 = document.createElement("div"), div_xlm_1 = document.createElement("div"), div_hxk_2 = document.createElement("div"), div_hxk_3 = document.createElement("div");
        var id_data_hxk1 = new Array("caixing", "dianzan", "jinli", "ku", "lengzhu", "liliang", "lihai", "liulei", "meme", "meiyankan", "pibei", "shufu", "taiqiangle", "weixiao", "xiezuoye", "yihuo"), text_data_hxk1 = new Array("菜醒", "点赞", "锦鲤", "酷", "愣住", "力量", "厉害", "流泪", "么么", "没眼看", "疲惫", "舒服", "太强了", "微笑", "写作业", "疑惑");
        var id_data_xlm1 = new Array("ok", "baobao", "chaoxiao", "chuizhuo", "haipa", "jueduibumo", "molei", "renjianrenai", "tingzhisikao", "xiwangzhihua", "xingxingyan", "yanbaba", "yihuo", "youhaoshoushi", "zhishizengjia", "zuodedaoma"), text_data_xlm1 = new Array("OK", "抱抱", "嘲笑", "捶桌", "害怕", "绝对不摸", "抹泪", "人见人爱", "停止思考", "希望之花", "星星眼", "眼巴巴", "疑惑", "友好手势", "知识增加", "做得到吗");
        var id_data_hxk2 = new Array("xuegao", "xiaoku", "woshale", "tianre", "sikao", "shuijiao", "shengfapenwu", "paobu", "naoketeng", "naicha", "liuhan", "jiandaoshou", "huachuan", "huaji", "hongbao", "emmm"), text_data_hxk2 = new Array("雪糕", "笑哭", "我傻了", "天热", "思考", "睡觉", "生发喷雾", "跑步", "脑壳疼", "奶茶", "流汗", "剪刀手", "划船", "滑稽", "红包", "emmm");
        var id_data_hxk3 = new Array("bainianla", "daxuezhang", "chijiaozi", "chimamaxiang", "go go go", "fahongbaola", "fangbianpao", "fangyanhua", "fudao", "ganfan", "gongxifacai", "kaixin", "qiangdaojukuan", "xiexie", "xinnianhao", "xingxingyan"), text_data_hxk3 = new Array("拜年啦", "打雪仗", "吃饺子", "吃嘛嘛香", "go go go", "发红包啦", "放鞭炮", "放烟花", "福到", "干饭", "恭喜发财", "开心", "抢到巨款", "谢谢", "新年好", "星星眼");
        div_hxk_1.innerHTML = createHTML(id_data_hxk1, text_data_hxk1, "hxk");
        div_xlm_1.innerHTML = createHTML(id_data_xlm1, text_data_xlm1, "xlm");
        div_hxk_2.innerHTML = createHTML(id_data_hxk2, text_data_hxk2, "hxk");
        div_hxk_3.innerHTML = createHTML(id_data_hxk3, text_data_hxk3, "hxk");
        var x = document.getElementById('sections-vm'), y = x.parentNode;
        div_hxk_1.onclick = function (event) {
            click_fun(id_data_hxk1, text_data_hxk1, event, "华小科");
        };
        div_xlm_1.onclick = function (event) {
            click_fun(id_data_xlm1, text_data_xlm1, event, "小南莓");
        };
        div_hxk_2.onclick = function (event) {
            click_fun(id_data_hxk2, text_data_hxk2, event, "华小科");
        };
        div_hxk_3.onclick = function (event) {
            click_fun(id_data_hxk3, text_data_hxk3, event, "华小科");
        };
        y.insertBefore(div_hxk_1, x);
        y.insertBefore(div_hxk_2, x);
        y.insertBefore(div_hxk_3, x);
        y.insertBefore(div_xlm_1, x);
    })();
})();